package com.srd.phone.utils.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import java.util.ArrayList;
import java.util.List;

public class HornViewFlipper extends ViewFlipper {

    private int countShow;

    List<String> hornList = new ArrayList<>(); //小喇叭数据集合，现在是测试数据

    public HornViewFlipper(Context context) {
        this(context, null);
    }

    public void setData(List<String> hornList0){
        hornList = hornList0;
        TextView tv = (TextView) getChildAt(getDisplayedChild());
        tv.setText(hornList.get(0));
    }

    public HornViewFlipper(Context context, AttributeSet attrs) {
        super(context, attrs);
        Animation inAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
                0f);
        inAnimation.setDuration(500);
        Animation outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
                0f);
        outAnimation.setDuration(500);
        setInAnimation(inAnimation);
        setOutAnimation(outAnimation);
    }

    @Override
    public void showNext() {
        super.showNext();
        countShow++;
        final int value = countShow % 10;
        TextView tv = (TextView) getChildAt(getDisplayedChild());
        tv.setText(hornList.get(value));
        tv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "点击值为："+hornList.get(value), Toast.LENGTH_SHORT).show();
            }
        });
    }
}
